package com.sxt.controller;

import com.sxt.common.validator.ValidatorUtil;
import com.sxt.domain.BusCustomer;
import com.sxt.query.BusCustomerQuery;
import com.sxt.service.BusCustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;


/**
 * @Description: 客户控制类
 */
@RestController
@RequestMapping("customer")
public class BusCustomerController {
    @Autowired
    private BusCustomerService busCustomerService;

    /**
     * 客户的分页查询
     *
     * @param query
     * @return
     */
    @RequestMapping("page.do")
    public Object page(BusCustomerQuery query) {
        return busCustomerService.queryPage(query);
    }

    /**
     * 新增客户
     *
     * @param busCustomer
     * @return
     */
    @RequestMapping("add.do")
    public Object add(BusCustomer busCustomer) {
        // 数据格式校验
        ValidatorUtil.validator(busCustomer);
        return busCustomerService.add(busCustomer);
    }

    /**
     * 修改客户信息
     *
     * @param busCustomer
     * @return
     */
    @RequestMapping("update.do")
    public Object update(BusCustomer busCustomer) {
        // 数据格式校验
        ValidatorUtil.validator(busCustomer);
        return busCustomerService.update(busCustomer);
    }

    /**
     * 导出符合条件的客户信息
     *
     * @param query
     * @param response
     */
    @RequestMapping("export.do")
    public void export(BusCustomerQuery query, HttpServletResponse response) throws Exception {
        busCustomerService.exportCustomer(query, response);
    }

    /**
     * 批量导入客户信息
     *
     * @param file
     * @return
     * @throws Exception
     */
    @RequestMapping("import.do")
    public Object customerImport(@RequestParam("customers") MultipartFile file) throws Exception {
        return busCustomerService.batchAddCustomer(file);
    }

}
